package com.ct.controller.shipping;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.shipping.model.po.ChuanYuanKuGongZuoSavePO;
import com.ct.application.shipping.model.po.ChuanYuanKuGongZuoSearchPO;
import com.ct.application.shipping.model.vo.ChuanYuanKuGongZuoVO;
import com.ct.application.shipping.service.ChuanYuanKuGongZuoService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import com.ct.shipping.orm.ChuanYuanKuGongZuoDO;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 船员库工作经验配置
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = "船员库工作经验",path="/api/v1/chuanyuankugongzuo",code = "R1000",sorted = 13)
public class ChuanYuanKuGongZuoController extends BaseController {

    @Resource
    private ChuanYuanKuGongZuoService chuanYuanKuGongZuoService;

    /**
     * 查询船员库工作经验列表
     * @param chuanYuanKuGongZuoSearchPO
     * @return
     */
    @PostMapping("/chuanyuankugongzuo/list")
    @PermissionApi(title = "查询船员库工作经验列表",path="/api/v1/chuanyuankugongzuo/list",code = "R1001",sorted = 1)
    public Page<ChuanYuanKuGongZuoVO> findChuanYuanKuGongZuos(@Validated @RequestBody ChuanYuanKuGongZuoSearchPO chuanYuanKuGongZuoSearchPO) {
        return chuanYuanKuGongZuoService.findChuanYuanKuGongZuo(chuanYuanKuGongZuoSearchPO);
    }

    /**
     * 保存和更新
     *
     * @param savePO
     * @return
     */
    @PostMapping("/chuanyuankugongzuo/saveupdate")
    @ApiLog("船员库工作经验保存和更新")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员库工作经验保存和更新",path="/api/v1/chuanyuankugongzuo/saveupdate",code = "R1003",sorted = 3)
    public ChuanYuanKuGongZuoVO saveUpdateChuanYuanKuGongZuo(@Validated @RequestBody ChuanYuanKuGongZuoSavePO savePO) {
        if (Objects.nonNull(savePO.getId())){
            return chuanYuanKuGongZuoService.updateChuanYuanKuGongZuo(savePO);
        }else {
            return chuanYuanKuGongZuoService.saveChuanYuanKuGongZuo(savePO);
        }
    }

    /**
     * 获取上一次新增的对象数据
     */
    @PostMapping("/chuanyuankugongzuo/findLastChuanYuanKuGongZuo")
    @PermissionApi(title = "获取上一次新增的对象数据",path="/api/v1/chuanyuankugongzuo/findLastChuanYuanKuGongZuo",code = "R1007",sorted = 7)
    public ChuanYuanKuGongZuoDO findLastChuanYuanKuGongZuo() {
        return chuanYuanKuGongZuoService.findLastChuanYuanKuGongZuo();
    }

    /**
     * 根据id查询船员库工作经验
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuankugongzuo/get/{id}")
    @PermissionApi(title = "根据id查询船员库工作经验",path="/api/v1/chuanyuankugongzuo/get/{id}",code = "R1004",sorted = 4)
    public ChuanYuanKuGongZuoVO getChuanYuanKuGongZuoById(@PathVariable("id") Long id) {
        return chuanYuanKuGongZuoService.getChuanYuanKuGongZuo(id);
    }


    /**
     * 根据id删除船员库工作经验
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuankugongzuo/del/{id}")
    @ApiLog("根据id删除船员库工作经验")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除船员库工作经验",path="/api/v1/chuanyuankugongzuo/del/{id}",code = "R1005",sorted = 5)
    public Boolean delChuanYuanKuGongZuoById(@PathVariable("id") Long id) {
        return chuanYuanKuGongZuoService.delChuanYuanKuGongZuo(id);
    }

    /**
     * 修改状态
     *
     * @return
     */
    @PostMapping("/chuanyuankugongzuo/update/status")
    @ApiLog("船员库工作经验修改状态")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员库工作经验修改状态",path="/api/v1/chuanyuankugongzuo/update/status",code = "R1006",sorted = 6)
    public Boolean updateStatus(@Validated @RequestBody StatusRequest statusRequest) {
        return chuanYuanKuGongZuoService.updateStatus(statusRequest);
    }
}
